from typing import List

import matplotlib.pyplot as plt
from matplotlib import font_manager

from .. import font


class FontFamily:
    
    ARIAL_UNICODE_MS = "Arial Unicode MS"
    TIMES_NEW_ROMAN = "Times New Roman"
    
    
class FontProperties:
    TIMES_SONG = "ST-Song"
        
        
class TickDirection:
    
    IN = "in"
    OUT = "out"
    
    
class TickItemLoction:
    
    TOP = "top"
    BOTTOM = "bottom"
    RIGHT = "right"
    LEFT = "left"
    

class GridStyle:
    
    SOLID = '-'
    DASH = '--'
    

class GridAxis:
    
    X = 'x'
    Y = 'y'
    BOTH = 'both'
    

class AxesLabelSize:
    
    XX_SMALL = 'xx-small'
    X_SMALL = 'x-small'
    SMALL = 'small'
    MEDIUM = 'medium'
    LARGE = 'large'
    X_LARGE = 'x-large'
    XX_LARGE = 'xx-large'
    
    
class LegendFontSize:
    
    XX_SMALL = 'xx-small'
    X_SMALL = 'x-small'
    SMALL = 'small'
    MEDIUM = 'medium'
    LARGE = 'large'
    X_LARGE = 'x-large'
    XX_LARGE = 'xx-large'
    

class FigurePadDirection:
    
    VIRTICAL = 'h'
    HORIZONTAL = 'w'


def set_tick_direction(tick: str, direction: TickDirection):
    
    """设置刻度线的方向"""
    
    plt.rcParams[f"{tick}tick.direction"] = direction
    
    
def set_tick_label_size(tick: str, labelsize: float):
    
    """设置刻度标识大小"""
    
    plt.rcParams[f"{tick}tick.labelsize"] = labelsize
    
    
def enable_tick(tick: str, location: TickItemLoction, useOrNot: bool):
    
    """设置在相应位置使用坐标轴"""
    
    plt.rcParams[f"{tick}tick.{location}"] = useOrNot


def enable_tick_label(tick: str, location: TickItemLoction, useOrNot: bool):
    
    """设置是否在相应位置使用坐标轴刻度"""
    
    plt.rcParams[f"{tick}tick.label{location}"] = useOrNot

    
def set_font_family(family: FontFamily):
    
    """设置字体簇"""
    
    plt.rcParams["font.family"] = family
    

def set_font_size(size: float):
    
    """设置全局字体大小"""
    
    plt.rcParams["font.size"] = size
    

def set_figure_size(size: List[int]):
    
    """设置图片大小"""
    
    plt.rcParams["figure.figsize"] = size
    
    
def enable_figure_constrained_layout(useOrNot: bool):
    
    """设置是否使用分布约束"""
    
    plt.rcParams["figure.constrained_layout.use"] = useOrNot
    
    
def set_figure_pad(direction: FigurePadDirection, padSize: float):
    
    """设置图像相应方向上的留白"""
    
    plt.rcParams[f"figure.constrained_layout.{direction}_pad"] = padSize
    

def enable_axes_unicode_minus(useOrNot: bool):
    
    """设置坐标轴中的符号是否使用unicode编码"""
    
    plt.rcParams["axes.unicode_minus"] = useOrNot
    
    
def set_axes_label_size(size: int or AxesLabelSize):
    
    """设置标签字体大小"""
    
    plt.rcParams["axes.labelsize"] = size
    

def set_grid_style(style: GridStyle):
    
    """设置网格线型"""
    
    plt.rcParams["grid.linestyle"] = style
    
    
def set_grid_width(width: float):
    
    """设置网格线宽"""
    
    plt.rcParams["grid.linewidth"] = width
    
    
def enable_grid(useOrNot: bool):
    
    """设置是否使用网格"""
    
    plt.rcParams["axes.grid"] = useOrNot
    
    
def set_grid_axis(axisGrid: GridAxis):
    
    """设置网格轴向"""
    
    plt.rcParams["axes.grid.axis"] = axisGrid


def set_legend_font_size(size: float):
    
    """设置图例字体大小"""
    
    plt.rcParams["legend.fontsize"] = size
    

def get_font(font_name: FontProperties) -> font_manager.FontProperties:
    
    return font_manager.FontProperties(fname=f"{font.get_dir_name()}/{font_name}.ttf")
    